#include "MenuConectar.h"
#include <iostream>
#include "MenuMultijugador.h"
#include "ErrorDeConexion.h"
#include <string>

MenuConectar::MenuConectar()
{
	Glib::RefPtr<Gtk::Builder> refBuilder = Gtk::Builder::create();
	refBuilder->add_from_file("./Cliente/MenuConectar.glade");

	refBuilder->get_widget("MenuConectar", main);
		
	refBuilder->get_widget("conectar", botonConectar);
	botonConectar->signal_clicked().connect(sigc::mem_fun(*this, &MenuConectar::on_buttonConectar_clicked));
	
	refBuilder->get_widget("txtIP", ip);
	refBuilder->get_widget("txtPuerto", puerto);
	
	stringstream puertoDefault;
	puertoDefault << PUERTO_DEFAULT;
	
	ip->set_text(IP_DEFAULT);
	puerto->set_text(puertoDefault.str());
}

void MenuConectar::correr() {
	Gtk::Main::run(*main);
}

void MenuConectar::on_buttonConectar_clicked() {
	main->hide();
	MainJuegoLocal m(ip->get_text(),atoi(puerto->get_text().data()));
	if ( m.getEstadoConexion()){
		MenuMultijugador menumulti(&m);
		menumulti.correr();
	}
	else
	{
		ErrorDeConexion e;
		e.correr();
	}
	correr();
}


MenuConectar::~MenuConectar()
{
	
}

